/*
 * TMap Designer - A Thematic Map design software
 * Copyright (C) 2006 World Health Organization
 * http://www.who.int
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 */
package who.tmap.toolkit.dao;

import java.awt.Color;
import org.jdom.Element;

import who.tmap.dao.TMapDAOException;
import who.tmap.toolkit.shape.MapShape;
import who.tmap.toolkit.shape.impl.MapShapeFactory;
import who.tmap.util.MiscHelper;

/**
 * @author stl
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
public abstract class BaseMapShapeDAO implements MapShapeDAO {

    protected MapShapeFactory msf =MapShapeFactory.getInstance();
    protected MiscHelper miscHelper =new MiscHelper();
    
    public Element save( MapShape mapShape ) throws TMapDAOException {
        return new Element( "Shape" );
    }
    
    /**
     * Get a Color from a hexadecimal format (alpha red blue green)
     * Find a more efficient way to do that later
     * 
     * @param hexa
     * @return
     */
    protected Color getColorFromHexa( String hexa ) {
        Color color =null;
        
        if ( !"".equals( hexa ) ) { 
	        int alpha =Integer.parseInt( hexa.substring( 0, 2 ), 16 );
	        int red =Integer.parseInt( hexa.substring( 2, 4 ), 16 );
	        int green =Integer.parseInt( hexa.substring( 4, 6 ), 16 );
	        int blue =Integer.parseInt( hexa.substring( 6 ), 16 );

	        color =new Color( red, green, blue, alpha );
        }
        
        return color; 
    }
    

    
}
